#include <iostream>
#include <cassert>
using namespace std;


struct ListNode{
	int val;
	ListNode *next;
	ListNode(int x) : val(x), next(NULL){}
};

// 根据n个元素的数组arr创建一个链表, 并返回链表的头
ListNode* createLinkedList(int arr[], int n){
	if(n == 0)
		return NULL;
	ListNode* head = new ListNode(arr[0]);
	ListNode* curNode = head;
	for(int i = 1; i < n; i++){
		curNode->next = new ListNode(arr[i]);
		curNode = curNode->next;
	}
	return head;
}

// 打印以head为头结点的链表信息内容
void printLinkedList(ListNode* head){
	ListNode* curNode = head;
	while(curNode != NULL){
		cout << curNode->val << " -> ";
		curNode = curNode->next;
	}
	cout << "NULL" << endl;
	return;
}	
// 释放以head为头结点的链表空间
void deleteLinkedList(ListNode* head){
	ListNode* curNode = head;
	while(curNode != NULL){
		ListNode* delNode = curNode;
		curNode = curNode->next;
		delete delNode;
	}
	return;
}

// 在链表中查找指定值元素
ListNode* findNode(ListNode* head, int x){

    ListNode* curNode = head;
    while(curNode != NULL){
        if(curNode->val == x)
            return curNode;
        curNode = curNode->next;
    }
    return NULL;
}
